package com.hmdp.config;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import com.hmdp.properties.AliyunProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageClientConfig {
    @Autowired
    private AliyunProperties aliyunProperties;

    @Bean
    @ConditionalOnMissingBean
    public Client createClient() throws Exception {
        Config config = new Config()
                .setAccessKeyId(aliyunProperties.getAccessKeyId())
                .setAccessKeySecret(aliyunProperties.getAccessKeySecret())
                .setEndpoint("dysmsapi.aliyuncs.com");

        return new Client(config);
    }
}
